package com.itcast.demoone

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class PageOneActivity : AppCompatActivity() {

    // 定义一个常量
    private val TAG = "itHeiMa-A"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        Log.d(TAG, "onCreate-A页面")

        enableEdgeToEdge()
        setContentView(R.layout.activity_page_one)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 1. 获取按钮监听点击
        val btn = findViewById<Button>(R.id.btn_action_next)
        btn.setOnClickListener {
            // 1.1 创建一个Intent对象
            val intent = Intent(this, PageTwoActivity::class.java)
            // 1.2 跳转携带参数
            intent.putExtra("name", "张三")
            intent.putExtra("age", 18)
            // 1.3 跳转
            startActivity(intent)
        }
    }

    override fun onStart() {
        super.onStart()
        Log.d(TAG, "onStart-A页面")
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG, "onResume-A页面")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG, "onPause-A页面")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG, "onStop-A页面")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy-A页面")
    }

    override fun onRestart() {
        super.onRestart()
        Log.d(TAG, "onRestart-A页面")
    }
}